﻿Imports System.Data
Imports System.Data.Odbc
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports Entidades

Public Class DBProducto
    Public cn As OdbcConnection
    Public con As SqlConnection
     Sub New()
        cn = New OdbcConnection("UID=pruebasexto" & _
          ";PWD=pruebasexto123" & _
          ";DATABASE=pruebasexto" & _
          ";SERVER=db4free.net" & _
          ";DRIVER={MySQL ODBC 3.51 Driver};")
    End Sub

    Function AltaProducto(ByVal nodo As Producto) As Boolean
        Try
            Try
                Dim cmd As OdbcCommand = New OdbcCommand("{call Alta_producto (?,?,?)}", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.AddWithValue("@nom", nodo.pid1)
                cmd.Parameters.AddWithValue("@prec", nodo.pid2)
                cmd.Parameters.AddWithValue("@id_c", nodo.pid3)

                cn.Open()
                cmd.ExecuteNonQuery()

            Catch o As OdbcException
                MsgBox(o.Message.ToString)
                Return False
            Finally
                cn.Close()
            End Try
            Return True

        Catch ex As Exception


        End Try
        Return False

    End Function
    Function BajaProducto(ByVal nodo As Producto) As Boolean
        Try
            Try
                Dim cmd As OdbcCommand = New OdbcCommand("{call Baja_producto (?,?,?)}", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.AddWithValue("@id", nodo.pid)

                cn.Open()
                cmd.ExecuteNonQuery()

            Catch o As OdbcException
                MsgBox(o.Message.ToString)
                Return False
            Finally
                cn.Close()
            End Try
            Return True

        Catch ex As Exception


        End Try
        Return False

    End Function
    Function ModificacionProducto(ByVal nodo As Producto) As Boolean
        Try
            Try
                Dim cmd As OdbcCommand = New OdbcCommand("{call Modificacion_producto (?,?,?)}", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.AddWithValue("@nomb", nodo.pid1)
                cmd.Parameters.AddWithValue("@pre", nodo.pid2)
                cmd.Parameters.AddWithValue("@id_ca", nodo.pid3)

                cn.Open()
                cmd.ExecuteNonQuery()

            Catch o As OdbcException
                MsgBox(o.Message.ToString)
                Return False
            Finally
                cn.Close()
            End Try
            Return True

        Catch ex As Exception


        End Try
        Return False

    End Function
    Function Consultaproducto() As DataSet

        Dim conn As SqlConnection = Nothing

        Dim ds As New DataSet

        Dim rdr As SqlDataReader = Nothing


        Try
            Dim cmd As SqlCommand = New SqlCommand("{call Consulta_producto ()}", con)
            cmd.CommandType = CommandType.StoredProcedure


            Dim dap As New SqlDataAdapter
            dap.SelectCommand = cmd
            dap.Fill(ds)


            Return ds


        Catch ex As Exception
            MsgBox(ex.ToString)
            Return ds

        End Try
    End Function
End Class
